<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
     <%@ page import="java.sql.*" %>
     <%@ page import="java.util.*"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<LINK REL=stylesheet HREF="css/iframe.css" TYPE="text/css">
</head>
<body>
<%
  Connection conn=null;
   String name2=request.getParameter("id");
   System.out.println(name2);
   String name =null;
   if(request.getParameter("liu")==null){
      name = new String(name2.getBytes("iso8859-1"),"utf-8");
   }else{
	   name=name2;
   }
  // String name="北京";
  out.print("<h3>"+name+"高校</h3>");
  //
    int pageSize = 10;//每页显示记录数
    int listStep = 20;//最多显示分页页数
    int pages = 1;    //默认显示第一页
    int rowCount;        //记录总数
    int pageCount;      //总页数
   
    //取得待显示页码
    if (request.getParameter("pages") != null) {
           pages = Integer.parseInt(request.getParameter("pages")); 
            }
    int recordBegin=(pages-1)*pageSize  ;//每页显示的一个记录
    int listBegin = (pages- (int) Math.ceil((double) listStep / 2));//从第几页开始显示分页信息
    int listend = pages + listStep/2;//分页信息显示到第几页
  try
  {
     Class.forName("com.mysql.jdbc.Driver");
     conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/school1130","root","root");
     Statement stmt=conn.createStatement();
     Statement stmt1=conn.createStatement();
     Statement stmt2=conn.createStatement();
     Statement stmt3=conn.createStatement();
     Statement stmt4=conn.createStatement();
     Statement stmt5=conn.createStatement();
     ResultSet ra=stmt.executeQuery("select  school_num  from school  where( province LIKE '%"+name+"%' )limit "+recordBegin+",10"   );
     ResultSet sqlRst=stmt5.executeQuery("select count(school_num) from school where( province LIKE '"+name+"%' )");
     sqlRst.next();
     rowCount=sqlRst.getInt(1);
     System.out.println("llllllll"+rowCount);
     //out.print(rowCount);
     
     ResultSet rb=null;
	 ResultSet rc=null;
	 ResultSet rd=null;
	 ResultSet re=null;
     List<String> str_list = new ArrayList<String>(); 
     while(ra.next()){
    	  str_list.add(ra.getString(1));
    	  request.setAttribute("str_list",str_list);
    	 } 
         List  ps=(List)request.getAttribute("str_list");
       //计算总页数
         pageCount=(rowCount+pageSize-1)/pageSize;
       //调整待显示的页码
       if(pages>pageCount)  pages=pageCount; 
       if(pageCount>0){ra.absolute((pages-1)*pageSize+1);}
       
       if (listBegin < 1) {
    	   listBegin = 1;
       }
      
       if (listend > pageCount) {
         listend = pageCount + 1;
       } 
            
    %>   
         

         <div id="fashionlist">
         <% 
    	 for(int i=0;i<str_list.size();i++)
    	 {	 // out.print(ps.get(i));
    		 String image_url="images/"+ps.get(i)+".jpg";
    	 try{
			   
		      rb=stmt1.executeQuery("select count(*) from school where school_num="+ps.get(i)   );
		      rc=stmt2.executeQuery("SELECT COUNT(post_num) FROM post WHERE account IN( SELECT account FROM user1,school  WHERE  (user1.school_num=school.school_num&&school.school_num="+ps.get(i)+" ) )")  ;
		      rd=stmt3.executeQuery("select introduction from school  where school_num=" +ps.get(i)   );
		      re=stmt4.executeQuery("select name from school  where school_num=" +ps.get(i)   );
		      %>
			    <div id="fashion">
			    <div id="image"  style="float:left; " >
			    <a href='which-uni.jsp?num=<%=ps.get(i)%>&iPage=1'><image  src=<%=image_url %> height="100px" width="100px"></image></a></div>
			    <div id="school_information" >
			    
			    <% 
			    while(re.next()){
			    out.print("<h4><a href='which-uni.jsp?num="+ps.get(i)+"&iPage=1' target='_parent''>");
			    out.print(re.getString(1));
			    out.print("</a></h4> ");}
			     
			    out.print("<a href='which-uni.jsp?num="+ps.get(i)+"&iPage=1' target='_parent''>关注量：</a><a href='which-uni.jsp?num="+ps.get(i)+"&iPage=1' target='_parent''> ");
			     while(rb.next()){
			    Integer a= rb.getInt(1);
			     if (a==0) {out.println("0");}
			     else{out.println(""+a);}}
			    out.print("</a><br/> ");
			    
			    out.print("<a href='which-uni.jsp?num="+ps.get(i)+"&iPage=1' target='_parent''>帖子数：</a><a href='which-uni.jsp?num="+ps.get(i)+"&iPage=1' target='_parent''> ");
			    while(rc.next()){
			    Integer a= rc.getInt(1);
			     if (a==0) {out.println("0");}
			     else{out.println(""+a);}}
			    out.print("</a><br/><a href='which-uni.jsp?num="+ps.get(i)+"&iPage=1' target='_parent''> ");
			    
			    while(rd.next()){  
			    String a=rd.getString(1);
			    if(a==null)  {out.print("");}
			    else{
			    out.print(a);}
			    out.print("</a>");}
			    %>
			   
			    </div> </div>
	

		<%    
			} catch(Exception e)
			  {
			     out.println(e.getMessage());
			  }  
		   	  

    	 }   	 
 
%>
     
  <% 	
  out.print("<div class='change'><ul>");
     //<显示上一页         
      if (pages> 1) {
                    %>
                   
    	            <%  out.print(  
                    " <li><a href=?pages=" + (pages - 1) + ">上一页</a></li> ");
                }//>显示上一页
                //<显示分页码
                System.out.println("shenxingboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+name);
                for (int j = listBegin; j < listend; j++) {
                    if (j != pages) {//如果j不等于当前页
                        out.print( 
                         "<li><a href='SelectAddressSchool.jsp?liu=a?pages=" + j +"?id="+ name+"'>" + j + "</a></li> ");
                    } else {
                        out.print("<li> " + j + "</li>");
                    }
                }//显示分页码>
                //<显示下一页
                System.out.println("");
                if (pages !=pageCount) {
                   out.print(
                    "<li><a href='SelectAddressSchool.jsp?liu=a?pages=" + (pages+ 1) +"?id="+name+"'>下一页</a></li> ");
                }
                out.print("</ul></div>");
                %>
		
    
  
 <%
  ra.close();

  stmt.close();
  rb.close();
  stmt1.close();
  rc.close();
  stmt2.close();
  rd.close();
  stmt3.close();
  re.close();
  stmt4.close();
  sqlRst.close();
  stmt5.close();
  conn.close();
  
  }
  catch(Exception e)
  {
     out.println(e.getMessage());
  }
%>

		 </body>
         </html>  